package com.zzyy.study.controller;

import com.zzyy.study.entities.User;
import com.zzyy.study.service.impl.UserWrapBatchService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther zzyy
 * @create 2024-04-01 22:27
 */
@RestController
public class AsyncController
{
    @Resource
    private UserWrapBatchService userBatchService;

    /**
     * 接口多线程并发执行 可能会出现的问题？
     * <p>
     * 异步，开启多线程，会阻塞Tomcat的线程
     *
     * @param userId
     * http://localhost:24331/async/async1?userId=33
     */
    @GetMapping("/async/async1")
    public User async1(Long userId) {
        return userBatchService.queryUserAsync(userId);
    }

    /***
     * 接口请求批量调用结合多线程 优化系统性能
     * http://localhost:24331/async/merge?userId=33
     * */
    @GetMapping("/async/merge")
    public User merge(Long userId)
    {
        return userBatchService.queryUser(userId);
        //return userWrapBatchQueueService.queryUser(userId);
    }
}
